#include <bits/stdc++.h>
using namespace std;
const int maxa = 2e6+10;
typedef long long ll;

//埃拉托色尼筛法(the Sieve of Eratosthenes)
vector<int> prim;
int mp[maxa];   //最小质因数
void cal_prim(int N){
    memset(mp, 0, sizeof(mp));
    for (ll i = 2; i < N; ++i) if(!mp[i]){
        for (ll j = i*i; j < N; j+=i) {
            mp[j] = i;
        }
    }
    for (int i = 2; i < maxa; ++i) {
        if(mp[i]) prim.push_back(i);
    }
}

bool isnp[maxa];
int pfactor[maxa];
vector<int> primes;

void init() {
    isnp[0] = isnp[1] = 1;
    pfactor[1] = 1;
    for (int i = 2; i < maxa; ++i) {
        if (!isnp[i]) {
            primes.emplace_back(i);
            pfactor[i] = i;
        }
        for (int x : primes) {
            if (1LL * x * i >= maxa) break;
            isnp[x * i] = 1;
            pfactor[x * i] = x;
            if (i % x == 0) break;
        }
    }
}

void exgcd(ll a, ll b, ll &x, ll &y){
    if(!b){x = 1, y = 0; return;}
    exgcd(b, a%b, y, x);
    y -= a/b*x;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
//    init();
    cal_prim(maxa);
    int T; cin >>T;
    while(T--){
        ll a, b; cin >> a >> b;
        ll c, d, e, f;
        ll g = __gcd(a, b);
        if(g > 1){
            c = (a + b) / g, d = b / g, e = 1, f = 1;
        }else{
            ll k = mp[b]; d = 1, f = b;
            if(!k) c = d = e = f = -1;
            else{
                while (f % k == 0) {
                    d *= k;
                    f /= k;
                }
                if(f == 1) c = d = e = f = -1;
                else{
                    exgcd(d, f, e, c);
                    e = -e;
                    while (c <= 0 || e <= 0) {
                        c += d;
                        e += f;
                    }
                    c *= a, e *= a;
                }
            }

//            if(!k) c = d = e = f = -1;
//            else{
//                d = 1, f = b;
//                while(k!=1 && f%k == 0) d*=k, f/=k;
//                if(f == 1) c = d = e = f = -1;
//                else{
//                    exgcd(d, f, e, c);
//                    e = -e;
//                    while(e<=0 || c <=0) e += f, c += d;
//                    e *= a, c *= a;
//                }
//            }
        }
        cout << c << " " << d << " " << e << " " << f << "\n";
//        if(c>0)assert((c*f-e*d)*b == a*d*f && c && d && e && f);
    }
    return 0;
}